package com.atguigu.cf.test;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;

/**
 * author: 封捷
 * date: 2023/1/29 16:47
 * version: 1.0
 */
public class Demo05TaskThenApply {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPool = ThreadPoolProvider.getThreadPool();

        // 后面任务既接收前面任务的结果，又有自己的返回值
        String taskFinalResult = CompletableFuture
                .supplyAsync(() -> "task prev result", threadPool)
                .thenApply(prevTaskResult -> {
                    System.out.println("这里是第二个任务，前面任务的结果是：" + prevTaskResult);

                    return "task behind result";
                }).get();

        System.out.println("taskFinalResult = " + taskFinalResult);
    }

}
